package com.siwei.mes.entity.experiment.cement;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 水泥-比表面积
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CementBbmj {
    @ApiModelProperty(value = "文案")
    private String wa = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "比表面积信息")
    private List<Bbmjcsy> bbmjsy = Collections.singletonList(new CementBbmj.Bbmjcsy());

    @Data
    @Accessors(chain = true)
    @ApiModel("比表面积信息")
    public static class Bbmjcsy {
        @ApiModelProperty(value = "标准样品密度")
        private String bzypmd = "";
        @ApiModelProperty(value = "标准样品空隙率")
        private String bzypkxl = "";
        @ApiModelProperty(value = "标准样品页面降落时间")
        private String bzypymjlsj = "";
        @ApiModelProperty(value = "标准样品比表面积")
        private String bzypbbmj = "";
        @ApiModelProperty(value = "被测样品密度")
        private String bcypmd = "";
        @ApiModelProperty(value = "被测样品空隙率")
        private String bcypkxl = "";
        @ApiModelProperty(value = "被测样品页面降落时间")
        private String bcypymjlsj = "";
        @ApiModelProperty(value = "被测样品密度比表面积")
        private String bcypbbmj = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CementBbmj entity = new CementBbmj();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CementBbmj.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CementBbmj.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CementBbmj entity = JsonUtils.getObject(objJson, CementBbmj.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

}
